<template>
	<div class="container">
		<el-dialog
			title="审核"
			:visible.sync="showDialog_copy"
			class="main_dialog_copy dialog800"
		>
			<el-form
				:inline="false"
				:model="mainform"
				class="demo-form-inline"
				ref="craftInfoRef"
				label-width="80px"
				key="userListFrom1"
				v-loading="loading"
			>
				<el-form-item label="用户名称" prop="uid">
					<span>{{ info.member ? info.member.nickname : "" }}</span>
				</el-form-item>
				<div class="goods_container_body main_taf main_table">
					<el-table
						ref="multipleTable"
						:data="mainform.list"
						element-loading-text="加载中"
						fit
						border
						highlight-current-row
					>
						<el-table-column label="序号" width="80">
							<template slot-scope="scope">{{ scope.$index + 1 }}</template>
						</el-table-column>
						<el-table-column
							label="物品名称"
							prop="goods_name"
							:show-overflow-tooltip="true"
						/>
						<el-table-column
							label="单位"
							prop="unit_title"
							:show-overflow-tooltip="true"
						>
						</el-table-column>
						<el-table-column
							label="单价"
							prop="price"
							:show-overflow-tooltip="true"
						>
						</el-table-column>

						<el-table-column label="预归还数量" prop="advance_num">
						</el-table-column>
						<el-table-column
							label="实归还数量"
							prop="num"
							:show-overflow-tooltip="true"
							width="140"
						>
							<template slot-scope="scope">
								<el-form-item
									label-width="10px"
									label=" "
									:prop="'list.' + scope.$index + '.num'"
								>
									<table-edit-input
										:number.sync="scope.row.num"
									></table-edit-input>
								</el-form-item>
							</template>
						</el-table-column>

						<!-- <el-table-column
							label="管理操作"
							prop="name"
							width="160"
							align="center"
							fixed="right"
							:show-overflow-tooltip="true"
						>
							<template slot-scope="scope">
								<el-link @click="handeleDel(scope.row, scope.$index)"
									>删除</el-link
								>
							</template>
						</el-table-column> -->
					</el-table>
				</div>
				<el-form-item label="备注" prop="uid">
					<span>{{ info.remark }}</span>
				</el-form-item>
			</el-form>
			<div slot="footer" class="dialog-footer">
				<el-button @click="handleComfirm(2)">驳回</el-button>
				<el-button
					type="primary"
					v-repeatClick
					:loading="saveloading"
					@click="handleComfirm(1)"
					>通过</el-button
				>
			</div></el-dialog
		>
	</div>
</template>
<script>
	import rules from "@/rules/warehouse/turnoverGoods/recordLend.js";
	import tableEditInput from "./tableEditInput.vue";
	import {
		turnoverOrder_info,
		turnoverOrder_check,
	} from "@/api/warehouse/warehouseTurnOrder";
	import { jsonStringifyBack } from "@/utils";
	export default {
		name: "",
		components: {
			tableEditInput,
		},
		props: {
			showDialog: {
				type: Boolean,
				default: false,
			},
			id: {
				type: Number | String,
				default: "",
			},
		},
		computed: {
			showDialog_copy: {
				get: function () {
					return this.showDialog;
				},
				set: function (newval) {
					this.$emit("update:showDialog", newval);
				},
			},
		},
		watch: {
			showDialog(val) {
				val ? this.turnoverOrder_info() : "";
			},
		},
		data() {
			return {
				rules: rules,
				mainform: {
					list: [],
				},
				info: {
					driver: {},
				},
				type: "",
				loading: false,
				saveloading: false,
				textarea: "",
				formsp: {},
			};
		},
		methods: {
			//获取用户信息
			getUser(data) {
				let uid = data.info.user_id;
				this.form.uid = uid;
			},
			// 清除用户的uid
			clearUid() {
				this.form.uid = "";
			},
			turnoverOrder_info() {
				let data = {
					id: this.id,
				};
				this.loading = true;
				turnoverOrder_info(data).then((res) => {
					if (res.errcode == 0) {
						this.type = res.data.info.type;
						this.info = res.data.info;
						res.data.info.order_list.map((e) => {
							e.goods_name = `${e.goods.name}【${e.goods_spu.spu_name.title}】`;
							e.unit_title = e.goods_spu.spu_unit.title;
						});
						this.mainform.list = res.data.info.order_list;
					} else {
						this.$message.error(res.errmsg);
					}
					this.loading = false;
				});
			},
			async handleComfirm(status) {
				let list = JSON.parse(
					JSON.stringify(this.mainform.list, jsonStringifyBack)
				);
				let arr = [];
				list.map((e) => {
					arr.push({
						id: e.id,
						num: e.num,
					});
				});
				// 1 通过 2 驳回
				let data = {
					id: this.id,
					status: status,
					list: JSON.stringify(arr),
				};
				await this.turnoverOrder_check(data);
				this.$emit("refresh");
				this.showDialog_copy = false;
				this.reset();
			},
			turnoverOrder_check(data) {
				return new Promise((resolve) => {
					turnoverOrder_check(data).then((res) => {
						if (res.errcode == 0) {
							this.$message.success("操作成功");
						} else {
							this.$message.error(res.errmsg);
						}
						resolve();
					});
				});
			},
			reset() {
				this.mainform.list = [];
				this.loading = false;
				this.info = { driver: {} };
			},
		},
	};
</script>
<style lang='scss' scoped>
.goods_container_header {
	display: flex;
	align-items: flex-start;
	flex-wrap: wrap;
	.btns {
		padding-left: 10px;
	}
}
.goods_container_body {
	margin-bottom: 15px;
}
.main_table /deep/ .el-table--small td .cell {
	height: auto;
	.el-form-item--mini.el-form-item,
	.el-form-item--small.el-form-item {
		margin-top: 10px;
	}
	.el-form-item__content {
		margin-top: 8px;
	}
}
.main_table /deep/ .el-table--small td {
	padding: 0;
}
.icon {
	margin-left: 5px;
	transform: translateY(1px);
}
</style>
